package exception;

public class ExceptionThrowDemo1 {
    public static void main(String[] args) {
        String phone="13722228989";
        try {
            checkPhone(phone);
        } catch (IllegalPhoneException e) {
            e.printStackTrace();
            //根据捕获到的异常完成具体的业务逻辑；
        }

        //String email="13722228989@gmail.com";
        //checkEmail(email);
    }
    static void checkPhone(String phone) throws IllegalPhoneException {
        if(phone!=null&&phone.length()!=11){
            //throw new IllegalPhoneException("请正确填写你的手机号");
            //Alt+enter,选择add exception...
            throw new IllegalPhoneException("手机号不合法");
        }
    }
    static void checkEmail(String email)throws Exception{
        if(email!=null&&!email.contains("@")){
            throw new Exception("邮箱格式不正确");//抛出检查异常（方法声明处必须抛出同类型或父类类型的异常）
        }
    }
}